# -*- coding: utf-8 -*-

# Define here the models for your spider middleware
#
# See documentation in:
# http://doc.scrapy.org/en/latest/topics/spider-middleware.html

from random import choice
from bd_spider.config import GenerationConfig


class UserAgentMiddleware(object):

    def __init__(self):
        self.user_agent = choice(GenerationConfig.USER_AGENTS)

    def process_request(self, request, spider):
        if self.user_agent:
            request.headers.setdefault('User-Agent', self.user_agent)
